package cn.itsource.pethome.basic.service.impl;

import cn.itsource.pethome.basic.mapper.BaseMapper;
import cn.itsource.pethome.basic.query.BaseQuery;
import cn.itsource.pethome.basic.service.IBaseService;
import cn.itsource.pethome.org.domain.Department;
import cn.itsource.pethome.org.util.DepartmentQuery;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {


    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void batchRemove(List<T> ts) {
        baseMapper.batchRemove(ts);
    }

    @Override
    public PageInfo<T> findAll(BaseQuery baseQuery) {
        PageHelper.startPage(baseQuery.getCurrentPage(), baseQuery.getPageSize());
        Page page= baseMapper.findAll(baseQuery);
        return new PageInfo<T>(page);
    }


}
